package lz4

import (
	"io"
	"servers/compress"

	"gitee.com/ameise84/e3utils/bytes_buffer"
	"github.com/pierrec/lz4/v4"
)

func Zip(src []byte) ([]byte, error) {
	wf := bytes_buffer.NewShiftBuffer(compress.BuffSize, 0, true)
	zw := lz4.NewWriter(&wf)
	if _, err := zw.Write(src); err != nil {
		return nil, err
	}
	if err := zw.Close(); err != nil {
		return nil, err
	}
	out, _ := wf.Fetch()
	return out, nil

}
func Unzip(src []byte) ([]byte, error) {
	rf := bytes_buffer.Warp(src)
	zr := lz4.NewReader(rf)
	return io.ReadAll(zr)
}
